home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #48 (Sep 89) / Doodats ƒ / Doodat #2 Source < prev    next >
Text File  |  1989-06-12  |  2KB  |  111 lines

  1. #define    NIL            0L
  2. /*
  3. **    Test a pointer for validity
  4. */
  5. #define    VALID_PTR(p)    ((long)(p) && ((long)(p) & 1L) == NIL)
  6. /*
  7. **    Test a handle for validity
  8. */
  9. #define    VALID_HNDL(h)    (VALID_PTR(h) && VALID_PTR((long)(*(h)) & 0x00FFFFFF))
  10. typedef struct
  11.     {
  12.     Handle                hndl;
  13.     Rect                frame;
  14.     unsigned char        type;
  15.     unsigned char        length;
  16.     short                data[];
  17.     }    ditl_list;
  18. /*************************************************
  19. **
  20. **    draw_ditl()    -    Lightspeed C Version
  21. **
  22. **    This routine reads in and draws the items in a
  23. **    Dialog Item List (DITL) resource.
  24. **
  25. **    In:    resource id of DITL
  26. **
  27. **    Out:    N/A
  28. **
  29. */
  30. void
  31. draw_ditl(ditl_id)
  32. short        ditl_id;
  33. {
  34. Handle            ditl_h;
  35. ditl_list        *ditl_p;
  36. PenState        save_pen;
  37. short            d_type, offset, num_items;
  38.  
  39. ditl_h = GetResource('DITL', ditl_id);
  40. if (ResError() != noErr || !VALID_HNDL(ditl_h))
  41.     return;
  42.  
  43. HLock(ditl_h);
  44. /*
  45. **    don't change pen behind the window's back
  46. */
  47. GetPenState(&save_pen);
  48. PenNormal();
  49. /*
  50. **    get the number of items in list
  51. */
  52. num_items = *((short *)(*ditl_h)) + 1;
  53. /*
  54. **    set pointer to first item in list
  55. */
  56. ditl_p = (ditl_list *)((*ditl_h) + sizeof(short));
  57. while  (num_items--)
  58.     {
  59.     switch (ditl_p->type & 0x7F)    /* mask out the item disabled bit */
  60.         {
  61.         case statText:
  62.             TextBox((char *)ditl_p->data, ditl_p->length, &(ditl_p->frame), teJustLeft);
  63.             break;
  64.         
  65.         case iconItem:
  66.             ditl_p->hndl = GetIcon(ditl_p->data[0]);
  67.             if (VALID_HNDL(ditl_p->hndl))
  68.                 {
  69.                 PlotIcon(&(ditl_p->frame), ditl_p->hndl);
  70.                 ReleaseResource(ditl_p->hndl);
  71.                 }
  72.             break;
  73.     
  74.         case picItem:
  75.             ditl_p->hndl = GetResource('PICT', ditl_p->data[0]);
  76.             if (VALID_HNDL(ditl_p->hndl))
  77.                 {
  78.                 DrawPicture((PicHandle)ditl_p->hndl, &(ditl_p->frame));
  79.                 ReleaseReource(ditl_p->hndl);
  80.                 }
  81.             break;
  82.             
  83.         case userItem:
  84.             if (EmptyRect(&(ditl_p->frame)))
  85.                 {
  86.                 PenPat(gray);
  87.                 MoveTo(ditl_p->frame.left, ditl_p->frame.top);
  88.                 LineTo(ditl_p->frame.right, ditl_p->frame.bottom);
  89.                 PenPat(black);
  90.                 }
  91.             else
  92.                 FrameRect(&(ditl_p->frame));
  93.             break;
  94.         }
  95. /*
  96. **    force offset to a word (even) boundary
  97. */
  98.     if ((offset = ditl_p->length) & 1)
  99.         offset++;
  100. /*
  101. **    advance pointer to next item
  102. */
  103.     ditl_p = (ditl_list *)((char *)ditl_p + sizeof(ditl_list) + offset);
  104.     }
  105. HUnlock(ditl_h);
  106. ReleaseResource(ditl_h);
  107. /*
  108. **    restore pen to original condition
  109. */
  110. SetPenState(&save_pen);
  111. }    /* end of draw_ditl() */